<form name="upload" action="admin_master_page.php?cmd=9" method="POST" enctype="multipart/form-data" >
<table width="680px">
	<tr>
        <td width="60px">Chọn File:</td>
        <td width="480px"><input type="file" name="userfile"></td>
    </tr>
	<tr>
        <td></td>
        <td>
			<input type="hidden" name="send" value="action" />
			<input type="submit" name="upload" value="Tải lên"> 
		</td>
    </tr>
</table>
</form> 
<p></p>
<table width="680px" class="table-list">
	<tr class="table-header">
        <td width="600px">Ảnh</td>
        <td width="80px">Xóa ảnh</td>
    </tr>

	<?php
	$n=0;
	foreach (glob("pics/*.jpg") as $filename)
	{
		$pics_arry[$n] = $filename;
		echo "<tr>";
		echo '<td>';
		echo '<img src="'.$pics_arry[$n].'" width="600x" height="250px">';
		echo '</td>';
		echo '<td align="center"><img src="img/ico_delete.png" onclick="showConfirm(\'Xác nhận\', \'Bạn có chắn muốn xóa không?\', \'admin_master_page.php?cmd=9&act=del&path='.$pics_arry[$n].'\')" class="del" /></td>';
		echo "</tr>";
	}
	?>
	
</table>
<?php
	// Xóa ảnh
	@$act = $_GET['act'];
	if($act == 'del')
	{
		$path = $_GET['path'];
		unlink($path);
		echo "<script>";
			echo "window.location = 'admin_master_page.php?cmd=9'";
		echo "</script>";
	}
?>

<?php
if(@$_POST["send"]=="action")
{
    $uploaddir = 'pics/'; 
    $ext = explode('.',$_FILES['userfile']['name']);
    if($ext[1]=='jpg' || $ext[1]=='JPG')
	{
        $id=rand();
        $filename=$id.'.'.$ext[1];
        $uploadfile = $uploaddir . $filename;      
            if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) 
			{ 
				$sizew = getimagesize($uploadfile);
				if($sizew[0] == '1600' && $sizew[1] == '518')
				{
                	echo "<script>showAlert('Thông báo!','Upload file thành công!','');</script>"; 
				}
				else 
				{
					echo "<script>showAlert('Lỗi!','Chỉ chấp nhận ảnh có kích thước 1600 x 518 px!','');</script>"; 
					unlink($uploadfile);
				}     
            } 
            else 
			{ 
                echo "<script>showAlert('Lỗi!','Có lỗi xảy ra khi Upload!','');</script>"; 
            } 
    }
    else 
	{
        echo "<script>showAlert('Lỗi!','File ảnh không đúng chuẩn (jpg,jpeg)!','');</script>";
    } 
}
?>






















